package com.extra_archive.project.iisu.model 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	/**
	 * @class name : BasicConfigManager
	 * @author : implict (http://extra-archive.com)
	 * @date : 2010. 4. 30.
	 * @description :
	 */
	public class BasicConfigManager extends EventDispatcher 
	{
		protected var _xmlURL : String;
		protected var _xmlLoader : URLLoader;
		protected var _configXML  : XML;
		
		public function BasicConfigManager(xmURL : String)
		{
			_xmlURL = xmURL;
			createXMLLoader();
		}
		
		//--------------------------------------------------------------------------
		//
		//    Public Methods
		//
		//--------------------------------------------------------------------------
		
		override public function toString() : String 
		{
			return "com.extra_archive.project.iisu.model.BasicConfigManager";
		}
		
		//--------------------------------------------------------------------------
		//
		//    Event Listeners
		//
		//--------------------------------------------------------------------------

		private function onIOError(event : IOErrorEvent) : void 
		{
			trace(this + " : onIOError");
		}

		private function onXMLLoadComplete(event : Event) : void 
		{
			trace(this + " : onXMLLoadComplete");
			
			_configXML = new XML(event.target.data);
			
			buildConfigItems();
		}
		
		//--------------------------------------------------------------------------
		//
		//    Private Methods
		//
		//--------------------------------------------------------------------------

		private function createXMLLoader() : void 
		{
			_xmlLoader = new URLLoader();
			_xmlLoader.addEventListener(Event.COMPLETE, onXMLLoadComplete);
			_xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			_xmlLoader.load(new URLRequest(_xmlURL));
		}
		
		/**
		 * xml 빌드 완료시 BasicModelEvent.LOAD_CONFIG_COMPLETE 디스패치해줘야 함.
		 * 
		 * @example :
		 * var listXMLList : XMLList = XMLList(_configXML.list.item);
		 * 	var i : uint, len : uint = listXMLList.length();
		 * 	for (i; i < len; ++i)
		 *	{
		 *		_listImgUrls[i] = listXMLList[i].img;
		 *	}
		 *	dispatchEvent(new ARModelEvent(ARModelEvent.LOAD_CONFIG_COMPLETE)); 
		 */
		protected function buildConfigItems() : void 
		{
			//TODO : implement!
		}
	}
}
